<?php
/**
 * Copyright (c) [2019] [吴跃忠]
 * [selibra] is licensed under the Mulan PSL v1.
 * You can use this software according to the terms and conditions of the Mulan PSL v1.
 * You may obtain a copy of Mulan PSL v1 at:
 * http://license.coscl.org.cn/MulanPSL
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v1 for more details.
 */

namespace Selibra\Bootstrap;

define("DEBUG_ENABLED", true);
define("SELIBRA_VERSION", "1.3.15");

use Selibra\Command\Annotations\Command;
use Selibra\Di\Container\ContainerBootstrap;
use Selibra\Di\Container\ContainerCollector;
use Selibra\Di\DI;
use Selibra\Tools\Console;
use Symfony\Component\Console\Application;


final class Bootstrap
{

    /**
     * @throws \Exception
     */
    public function run()
    {
        // 初始化容器
        ContainerBootstrap::init();
        // 查询所有的Command对象
        $objectList = ContainerCollector::getContainer()->collector()->selectObjectByContainerGroup(Command::class);

        $application = new Application();
        // 获取所有组件的命令
        $application->addCommands(array_map(fn($object) => DI::getObjectContext($object), $objectList));

        // 获取Swoole扩展版本号
        $swooleEx = new \ReflectionExtension("swoole");
        Console::logNF("Initialization successful. PHP version=" . phpversion(). ", Swoole version=" . $swooleEx->getVersion() . ", SeLibra version=" . SELIBRA_VERSION );

        // 启动
        $application->run();
    }
}
